package com.jinlejia.erp.ui.mine.adapter;

import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.freedom.yefeng.yfrecyclerview.YfListAdapter;
import com.freedom.yefeng.yfrecyclerview.YfSimpleViewHolder;
import com.jinlejia.erp.R;
import com.jinlejia.erp.databinding.ItemTransferapplySearchBinding;

import java.util.ArrayList;
import java.util.Map;

/**
 * Created by Administrator on 2018/6/8 0008.
 * 异动申请--选择共享店adapter
 */

public class TransferApplySearchShopAdapter extends YfListAdapter {
    private String keyWord;
//    private ArrayList<Map<String,Object>> data;

    public TransferApplySearchShopAdapter(ArrayList<Map<String, Object>> data, String keyWord) {
        super(data);
        this.keyWord = keyWord;
        mData = data;
    }

    public void setData(ArrayList<Map<String, Object>> data, String word) {
        setData(data);
        this.keyWord = word;
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateDataViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_transferapply_search, parent, false);
        //搜索结果
        return new ResultViewHolder(view);
    }

    @Override
    public RecyclerView.ViewHolder onCreateEmptyViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.empty_layout, parent, false);
        return new YfSimpleViewHolder(view);
    }

    @Override
    public void onBindDataViewHolder(RecyclerView.ViewHolder holder, int position) {
        ItemTransferapplySearchBinding binding = DataBindingUtil.getBinding(holder.itemView);
        Map<String, Object> map = (Map<String, Object>) mData.get(position);
        String tmp = "<font color=\"#FCCB00\">" + keyWord + "</font>";
        String str = map.get("shareStoreName").toString().replace(keyWord, tmp);
        binding.tvName.setText(Html.fromHtml(str));
        binding.getRoot().setTag(mData.get(position));
    }

    static final class ResultViewHolder extends RecyclerView.ViewHolder {
        public ResultViewHolder(View itemView) {
            super(itemView);
            DataBindingUtil.bind(itemView);
        }
    }
}
